package org.mspring.mlog.service;

import org.mspring.mlog.dao.ArticleTagEntityDao;
import org.mspring.mlog.entity.ArticleTagEntity;
import org.mspring.nbee.common.PageResult;
import org.mspring.nbee.db.dao.sql.builder.part.condition.SqlCondition;
import org.mspring.nbee.db.dao.sql.pager.SqlPager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2015-01-03 13:42:09
 */
@Service
public class ArticleTagEntityService {

    private static final Logger LOG = LoggerFactory.getLogger(ArticleTagEntityService.class);

    private ArticleTagEntityDao articleTagEntityDao;

    public ArticleTagEntity findById(long id) {
        return articleTagEntityDao.findById(id);
    }

    public PageResult<ArticleTagEntity> list(List<SqlCondition> conditions, SqlPager pager) {
        return articleTagEntityDao.listPage(conditions, pager);
    }

    /**
     * 删除文章对应的标签管理
     *
     * @param articleId
     * @return
     */
    @Transactional
    public boolean deleteByArticle(long articleId) {
        return articleTagEntityDao.deleteByArticle(articleId);
    }

    @Transactional
    public boolean insert(ArticleTagEntity articleTag) {
        return articleTagEntityDao.insert(articleTag);
    }

    @Transactional
    public boolean update(ArticleTagEntity articleTag) {
        return articleTagEntityDao.update(articleTag);
    }

    @Transactional
    public boolean deleteById(long id) {
        return articleTagEntityDao.deleteById(id);
    }

    @Autowired
    public void setArticleTagEntityDao(ArticleTagEntityDao articleTagEntityDao) {
        this.articleTagEntityDao = articleTagEntityDao;
    }

}